#pragma once

#include <optional>
#include <vector>
#include "sqlite_wrapper.h"

/// Repository result codes
#define REPO_SUCCESS 0
#define REPO_ERROR_DATABASE -1

/// @file base_repository.h
/// @brief Template base class for repository pattern implementation
/// 
/// This file defines a template base class that provides common CRUD operations
/// for all entity types. It reduces code duplication and ensures consistency
/// across different repositories.

/// @class BaseRepository
/// @brief Template base class for repository pattern
/// 
/// Provides common database operations for any entity type T.
/// Uses SQLite C API with RAII wrappers for database interactions.
/// 
/// @tparam T The entity type this repository manages
template<typename T>
class BaseRepository {
public:
    /// @brief Virtual destructor
    virtual ~BaseRepository() = default;

    /// @brief Create a new entity in the database
    /// @param entity Reference to the entity to create
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int create(T& entity) = 0;

    /// @brief Update an existing entity in the database
    /// @param entity Reference to the entity to update
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int update(const T& entity) = 0;

    /// @brief Remove an entity from the database by ID
    /// @param id The ID of the entity to remove
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int remove(int id) = 0;

    /// @brief Find an entity by ID
    /// @param id The ID of the entity to find
    /// @return Optional containing the entity if found, nullopt otherwise
    virtual std::optional<T> findById(int id) = 0;

    /// @brief Get all entities of type T
    /// @return Vector containing all entities
    virtual std::vector<T> findAll() = 0;
};